/*
 * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

package java.io;


/**
 * 用于写入字符文件的便利类。此类的构造函数假定默认字符编码和默认字节缓冲区大小是可接受的。
 * 若要自行指定这些值，请在 FileOutputStream 上构造 OutputStreamWriter。
 *
 * <p>文件是否可用或是否可以创建取决于底层平台。某些平台特别只允许一个
 * <tt>FileWriter</tt>（或其他文件写入对象）同时打开文件进行写入。
 * 在这种情况下，如果涉及的文件已经打开，此类中的构造函数将失败。
 *
 * <p><code>FileWriter</code> 用于写入字符流。
 * 若要写入原始字节流，请考虑使用 <code>FileOutputStream</code>。
 *
 * @see OutputStreamWriter
 * @see FileOutputStream
 *
 * @author      Mark Reinhold
 * @since       JDK1.1
 */

public class FileWriter extends OutputStreamWriter {

    /**
     * 根据文件名构造FileWriter对象。
     *
     * @param fileName  String 系统相关的文件名。
     * @throws IOException  如果指定的文件存在但是目录而不是常规文件，
     *                  不存在但无法创建，或者由于其他原因无法打开
     */
    public FileWriter(String fileName) throws IOException {
        super(new FileOutputStream(fileName));
    }

    /**
     * 根据文件名构造FileWriter对象，布尔值指示是否追加写入的数据。
     *
     * @param fileName  String 系统相关的文件名。
     * @param append    boolean 如果为<code>true</code>，则数据将写入
     *                  文件末尾而不是开头。
     * @throws IOException  如果指定的文件存在但是目录而不是常规文件，
     *                  不存在但无法创建，或者由于其他原因无法打开
     */
    public FileWriter(String fileName, boolean append) throws IOException {
        super(new FileOutputStream(fileName, append));
    }

    /**
     * Constructs a FileWriter object given a File object.
     *
     * @param file  a File object to write to.
     * @throws IOException  if the file exists but is a directory rather than
     *                  a regular file, does not exist but cannot be created,
     *                  or cannot be opened for any other reason
     */
    public FileWriter(File file) throws IOException {
        super(new FileOutputStream(file));
    }

    /**
     * Constructs a FileWriter object given a File object. If the second
     * argument is <code>true</code>, then bytes will be written to the end
     * of the file rather than the beginning.
     *
     * @param file  a File object to write to
     * @param     append    if <code>true</code>, then bytes will be written
     *                      to the end of the file rather than the beginning
     * @throws IOException  if the file exists but is a directory rather than
     *                  a regular file, does not exist but cannot be created,
     *                  or cannot be opened for any other reason
     * @since 1.4
     */
    public FileWriter(File file, boolean append) throws IOException {
        super(new FileOutputStream(file, append));
    }

    /**
     * Constructs a FileWriter object associated with a file descriptor.
     *
     * @param fd  FileDescriptor object to write to.
     */
    public FileWriter(FileDescriptor fd) {
        super(new FileOutputStream(fd));
    }

}
